function [TR,TV] = TimeSeriesLimCheck(Sig,ParamWN)
%TimeSeriesLimCheck - Check of time series limits
%
%   [TR,TV] = TimeSeriesLimCheck(Sig,ParamWN)
%
% Let Sig be either a rainfall time series Sig = [t R] or a rainfall and 
% velocity time series Sig = [t R V] and SigmaDA and Vmh be values of  
% ParamWN corresponding to the fields with esame name. 
% TR is 1 if R is higher than 10*SigmaDA(1) for are least two times and
% 0 elsewhere.  
% Under the condition that size(Sig,2) = 3, TV is 1 if V > VH for at least
% two times and 0 elsewhere, where VH is defined on the basis of Vmh (see 
% DefParam or DefParamInteractive for more information).
% If size(Sig,2) = 2, TV is empty.
%   
% See also DefParam, DefParamInteractive. 

% G. Teza, 2020

SigmaDA = ParamWN.SigmaDa;
Vmh = ParamWN.Vmh;

R = Sig(:,2);
IR = R > 10*SigmaDA; 

if sum(IR) >= 2
    TR = 1;
else
    TR = 0;
end
TR = logical(TR);

if size(Sig,2) == 3
    if isscalar(Vmh)
        VH = Vmh;
    elseif numel(Vmh) == 2
        VH = Vmh(2);
    elseif ismatrix(Vmh)
        if size(Vmh,2) == 2
            VH = max(Vmh(:,2));
        else
            VH = max(Vmh(:,3));
        end
    else
        VH = [];
    end
    if ~isempty(VH)
        V = Sig(:,3);
        IV = V > VH;
        if sum(IV) >= 2
            TV = 1;
        else
            TV = 0;
        end
        TV = logical(TV); 
    else
        TV = [];
    end
else
    TV = [];
end